package com.sugon.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 流的扁平化
 * @author luoy
 * @date 2018/7/8 0008 下午 10:34
 */
public class TestStream_flatmap {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("abccc", "cdf", "feg","dfc");
        //转换成字符串数组
        Stream<String[]> stream = list.stream().map(s -> s.split(""));

      /*  Stream<String> stringStream = list.stream().flatMap((String s) -> {
            String[] ss = s.split("");
            Stream<String> result = Arrays.stream(ss);
            return result;
        });*/
        //流的扁平化
        //stream.flatMap(array->Arrays.stream(array));
        Stream<String> stream1 = stream.flatMap(Arrays::stream);
        stream1.distinct().collect(Collectors.toList()).forEach(System.out::println);
    }
}


